<!-- 服务分类选择  -->
<template>
	<view>
		<!-- tab -->
		<uni-nav-bar title="服务分类选择" @clickLeft="goHome" left-icon="left" backgroundColor="#fff" color="#000"
			statusBar="true" />
		<!-- search -->
		<search @goSearch="goSearch" @clearKeyword="clearKeyword"></search>
		<!-- content -->
		<view class="main" v-if="serviceClassifyList.length > 0">
			<scroll-view class="scrollheight" scroll-y="true" :style="{height:setcollapseheight() + 'px'}">
				<view v-for="(item,index) in serviceClassifyList" :key="item.id" class="item"
					@click="chooseClassify(item)">
					<view class="left">
						<image src="@/static/socialized-service/farm-service/information.png"
							v-if="item.name === '资讯服务'" mode=""></image>
						<image src="@/static/socialized-service/farm-service/weibao.png" v-if="item.name === '维保服务'"
							mode=""></image>
						<image src="@/static/socialized-service/farm-service/lease.png" v-if="item.name === '租赁服务'"
							mode=""></image>
						<image src="@/static/socialized-service/farm-service/machinery.png"
							v-else-if="item.name === '农机服务'" mode=""></image>
						<image src="@/static/socialized-service/farm-service/agriculture.png"
							v-else-if="item.name === '助农服务'" mode=""></image>
						<image src="@/static/socialized-service/farm-service/process.png"
							v-else-if="item.name === '农产品加工服务'" mode=""></image>
						<image src="@/static/socialized-service/farm-service/anchor.png" v-if="item.name === '带货服务'"
							mode=""></image>
					</view>
					<view class="right">
						<view class="top">
							{{item.name}}
						</view>
						<template v-if="item.name !== '资讯服务'">
							<view class="center">
								<view class="center-item" v-for="(it,itIndex) in item.serviceProjects" :key="it.id"
									v-show="itIndex<=2" v-if="it.serviceProviderNo===serviceProviderNo">
									<view >{{it.name}} </view>
								</view>
								<view v-if="item.serviceProjects.length>3 && item.name!=='维保服务'" style="color: #80A7FF;">
									...
								</view>
							</view>
							<view class="bottom" v-if="item.name === '带货服务'">
								主播数：{{anchorNum}}
							</view>
							<div class="bottom" v-else>
								提供此服务方数：{{item.organizationNum}}家
							</div>
						</template>
						<view class="center1" v-else>
							<view class="center-item" v-for="(it,itIndex) in item.serviceProjects" :key="it.id"
								v-show="itIndex<=4">
								{{it.name}}
							</view>
						</view>

					</view>
				</view>
				<view class="bottom-ios-lineline">

				</view>
				<view class="bottom-ios-line">

				</view>
			</scroll-view>
		</view>
		<!-- noDate -->
		<view v-else>
			<view class="blank">
				<image src="@/static/blank.png" mode=""></image>
				<view class="nodata">
					暂无数据
				</view>
			</view>
		</view>
		<!-- loading -->
		<u-loading-icon :show="loading" size="36" />
		<!-- bottomTabar -->
		<bottomTabar />
		<view class="bottom-ios-line"></view>
	</view>
</template>

<script>
	import anchorAPI from '@/api/socialized-servce/farm-service/user/selectAnchor/index.js'
	import API from '@/api/socialized-servce/farm-service/normalUser/serviceSelect/serviceClassify/index.js'
	import bottomTabar from '../../components/normalUser-tabar/index.vue'
	import search from '../../components/search/index.vue'

	export default {
		components: {
			bottomTabar,
			search
		},
		data() {
			return {
				loading: false,
				originserviceClassifyList: [],
				serviceClassifyList: [],
				serviceProviderNo:'',
				serviceClassifyList1: [{
					name: '资讯服务',
					id: 'zx001',
					serviceProjects: [{
							name: '环境数据推送',
							id: 'zx001001'
						},
						{
							name: '农业资讯推送',
							id: 'zx001002'
						},
						{
							name: '政策法推送',
							id: 'zx001003'
						},
						{
							name: '行业资讯推送',
							id: 'zx001004'
						}
					]
				}],
				anchorNum: null
			}
		},
		mounted() {
			this.setcollapseheight()
			this.getServiceClassify()
			this.queryAnchor()
			this.serviceProviderNo=uni.getStorageSync('serviceProviderNo')
		},
		methods: {
			// 获取主播数量
			async queryAnchor() {
				let params = {
					richEntity: true,
					svcClassId: 23
				}
				let res = await anchorAPI.queryAnchor(params)
				if (res.code === 200) {
					this.anchorNum = res.data.length
				}

			},
			// 服务方分类
			async getServiceClassify() {
				if (this.loading) return
				this.loading = true
				let params = {
					richEntity: true,
					serviceProviderNo: uni.getStorageSync('serviceProviderNo')
				}
				let res = await API.serviceClassify(params)
				if (res.code === 200) {
					this.serviceClassifyList = res.data
					this.getOperateCladdify()
					this.loading = false

				} else {
					this.loading = true
				}
			},
			// 运营方分类
			async getOperateCladdify() {
				let params = {
					richEntity: true,
					serviceProviderNo: uni.getStorageSync('serviceProviderNo'),
					providerServiceTag: true
				}
				let res = await API.serviceClassify(params)
				if (res.code === 200) {
					let newList = res.data
					this.serviceClassifyList = [...newList, ...this.serviceClassifyList, ...this.serviceClassifyList1]
					this.originserviceClassifyList = this.serviceClassifyList
				}
				console.log(this.serviceClassifyList)
			},
			// 搜索
			goSearch(keyWord) {
				this.serviceClassifyList = this.originserviceClassifyList.filter(el => el.name.includes(keyWord))
			},
			clearKeyword() {
				this.serviceClassifyList = this.originserviceClassifyList
			},
			chooseClassify(item) {
				let url = ''
				uni.setStorageSync('serviceTypeNo', item.serviceTypeNo)
				uni.setStorageSync('serviceTypeName', item.name)
				if (item.name === '农机服务') {
					url = '/subPage1/socialized-service/farm-service/normalUser/my-arable/my-arable'
				}
				console.log(item.name);
				if (item.name === '租赁服务' || item.name === '助农服务' || item.name === '农产品加工服务' || item.name === '维保服务') {
					url =
						'/subPage1/socialized-service/farm-service/normalUser/serviceSelect/service-organization/service-organization'
				}
				if (item.name === '带货服务') {
					uni.setStorageSync('serviceTypeName1', item.name)
					let svcClassId = item.serviceProjects[0].svcClassId
					svcClassId = 24
					uni.setStorageSync('svcClassId', svcClassId)
					url = '/subPage1/socialized-service/farm-service/order/order'
				}
				if (item.name === '资讯服务') {
					uni.setStorageSync('serviceTypeName1', item.name)
					url = '/subPage1/socialized-service/farm-service/user/messageSubscription/index'
				}

				uni.redirectTo({
					url: url
				})
			},
			setcollapseheight() {
				let topheightone = uni.upx2px(260)
				let newheight = this.customBar + topheightone
				let winHeight = 0
				uni.getSystemInfo({
					success: function(res) {
						winHeight = res.windowHeight
					}
				});
				winHeight = parseInt(winHeight) - newheight
				// #ifndef H5
				winHeight = winHeight - 10

				// #endif
				return winHeight
			},
			goHome() {
				uni.switchTab({
					url: '/pages/socialized-service/selection-system/selection-system'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		width: 100%;
		height: 100%;
		margin-top: 20rpx;
		background: #F5F6FA;

		.item {
			display: flex;
			box-sizing: border-box;
			height: 200rpx;
			padding: 30rpx;
			margin: 0 40rpx;
			margin-bottom: 18rpx;
			background-color: #FFFFFF;
			box-shadow: 0px 3px 6px 1px rgba(0, 0, 0, 0.05);
			border-radius: 5px 5px 5px 5px;

			.left {
				width: 208rpx;
				height: 100%;
				margin-right: 20rpx;

				image {
					width: 208rpx;
					height: 100%;
				}
			}

			.right {
				width: calc(100% - 208rpx);
				height: 100%;

				.top {
					font-size: 32rpx;
					font-family: Source Han Sans CN-Bold, Source Han Sans CN;
					font-weight: bold;
					color: #91743E;
				}

				.center {
					margin-top: 15rpx;
					display: flex;
					width: 100%;

					.center-item {
						max-width: 50%;
						margin-right: 10rpx;
						padding: 2rpx 9rpx;
						background: #FFFFFF;
						border-radius: 28rpx;
						border: 2rpx solid #80A7FF;
						color: #80A7FF;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}

				.center1 {
					margin-top: 6rpx;
					display: flex;
					flex-wrap: wrap;
					width: 100%;

					.center-item {
						max-width: 50% !important;
						margin-right: 10rpx;
						padding: 2rpx 9rpx;
						background: #FFFFFF;
						border-radius: 28rpx;
						border: 2rpx solid #80A7FF;
						color: #80A7FF;
						margin-bottom: 10rpx;
						// overflow: hidden;
						// text-overflow: ellipsis;
						// white-space: nowrap;
					}
				}

				.bottom {
					margin-top: 15rpx;
					color: #5C5C5C;
					font-size: 24rpx;
				}
			}
		}

	}

	.blank {
		position: absolute;
		width: 100%;
		top: 50%;
		transform: translateY(-50%);
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		image {
			width: 200rpx;
			height: 200rpx;
		}

		.nodata {
			margin-top: 20rpx;
		}
	}
</style>